package pl.squeaky.mvc.generator;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;

public abstract class Generator {

	public abstract void generate(IFile file);
	
	public void save(IFile file, String content) {
		InputStream stream;
		try {
			stream = new ByteArrayInputStream(content.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
		
		try {
			file.create(stream, false, null);
		} catch (CoreException e) {
			throw new RuntimeException(e);
		}
	}

}